/*
* pps_bom
*/
package com.pitop.project.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.project.entity.ProjectCategory;
import com.pitop.project.service.ProjectCategorySV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 项目分类 控制器
 *
 * @author berton
 */
@RestController
@RequestMapping("/projectCategory")
@Slf4j
@Api(value = "项目分类控制器", description = "项目分类控制器")
public class ProjectCategoryCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private ProjectCategorySV projectCategorySV;

    /**
     * 查询ProjectCategory一个详情信息
     *
     * @param id   id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectCategory一个详情信息", notes = "查询ProjectCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public ProjectCategory load(Long id, String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        ProjectCategory projectCategory = projectCategorySV.load(id, code);
        log.info(JSON.toJSONString(projectCategory));
        return projectCategory;
    }


    /**
     * 根据条件id查询ProjectCategory一个详情信息
     *
     * @param id id
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectCategory一个详情信息", notes = "查询ProjectCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public ProjectCategory loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        ProjectCategory projectCategory = projectCategorySV.loadById(id);
        log.info(JSON.toJSONString(projectCategory));
        return projectCategory;
    }

    /**
     * 根据条件code查询ProjectCategory一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectCategory一个详情信息", notes = "查询ProjectCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public ProjectCategory loadByCode(@PathVariable String code) {
        if (code == null) {
            return null;
        }
        ProjectCategory projectCategory = projectCategorySV.loadByCode(code);
        log.info(JSON.toJSONString(projectCategory));
        return projectCategory;
    }


    /**
     * 根据条件name查询ProjectCategory一个详情信息
     *
     * @param name 项目分类名称
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectCategory一个详情信息", notes = "查询ProjectCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "项目名称", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/name/{name}")
    @ResponseBody
    public ProjectCategory loadByName(@PathVariable String name) {
        if (name == null) {
            return null;
        }
        ProjectCategory projectCategory = projectCategorySV.loadByName(name);
        log.info(JSON.toJSONString(projectCategory));
        return projectCategory;
    }


    /**
     * 查询ProjectCategory信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ProjectCategory信息集合", notes = "查询ProjectCategory信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<ProjectCategory> list(@RequestBody @ApiIgnore ProjectCategory projectCategory, Integer curPage, Integer pageSize) {
        Page<ProjectCategory> page = new Page<ProjectCategory>(pageSize, curPage);
        List<ProjectCategory> projectCategorys = projectCategorySV.list(projectCategory, page.genRowStart(), page.getPageSize());
        int total = projectCategorySV.count(projectCategory);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return projectCategorys;
    }

    /**
     * 查询ProjectCategory信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ProjectCategory信息集合", notes = "查询ProjectCategory信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<ProjectCategory> listByPk(Long id, String code, Integer curPage, Integer pageSize) {
        Page<ProjectCategory> page = new Page<ProjectCategory>(pageSize, curPage);
        List<ProjectCategory> projectCategorys = projectCategorySV.list(id, code, page.genRowStart(), page.getPageSize());
        int total = projectCategorySV.count(id, code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return projectCategorys;
    }

    /**
     * 统计ProjectCategory信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计ProjectCategory信息数量根据主键", notes = " 统计ProjectCategory信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String code) {
        return projectCategorySV.count(id, code);
    }

    /**
     * 统计ProjectCategory信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计ProjectCategory信息数量", notes = "统计ProjectCategory信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "分类名称,最大32个汉字，64个英文", paramType = "query"),
            @ApiImplicitParam(name = "englishName", value = "英文名", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody ProjectCategory projectCategory) {
        return projectCategorySV.count(projectCategory);
    }

    /**
     * 创建ProjectCategory
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建ProjectCategory", notes = "创建ProjectCategory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "分类名称,最大32个汉字，64个英文", paramType = "query"),
            @ApiImplicitParam(name = "englishName", value = "英文名", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public ProjectCategory build(@RequestBody @ApiIgnore ProjectCategory projectCategory) {
        projectCategorySV.save(projectCategory);
        return projectCategory;
    }

    /**
     * 修改ProjectCategory
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改ProjectCategory", notes = "修改ProjectCategory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "分类名称,最大32个汉字，64个英文", paramType = "query"),
            @ApiImplicitParam(name = "englishName", value = "英文名", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public ProjectCategory modify(@RequestBody @ApiIgnore ProjectCategory projectCategory) {
        projectCategorySV.modify(projectCategory);
        return projectCategory;
    }

    /**
     * 删除ProjectCategory
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除ProjectCategory", notes = "删除ProjectCategory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String code) {
        projectCategorySV.delete(id, code);
        return BeanRet.create(true, "删除ProjectCategory成功");
    }

}
